﻿namespace Jst.Common
{
    /// <summary>
    /// 通用返回信息类
    /// </summary>
    public class MessageModel<T>
    {
        /// <summary>
        /// 状态码
        /// </summary>
        public int status { get; set; } = 200;
        /// <summary>
        /// 操作是否成功
        /// </summary>
        public bool success { get; set; } = false;
        /// <summary>
        /// 返回信息
        /// </summary>
        public string msg { get; set; } = "";
        /// <summary>
        /// 开发者信息
        /// </summary>
        public string msgDev { get; set; }
        /// <summary>
        /// 返回数据集合
        /// </summary>
        public T response { get; set; }

        /// <summary>
        /// 文件流字节数组
        /// </summary>
        public byte[] FileBytes { get; set; }
        /// <summary>
        /// 返回类型
        /// </summary>
        public string ContentType { get; set; }

        /// <summary>
        /// 多个
        /// </summary>
        public List<string> list { get; set; }

        /// <summary>
        /// 返回成功
        /// </summary>
        /// <param name="msg">消息</param>
        /// <returns></returns>
        public static MessageModel<T> Success(string msg = "操作成功")
        {
            return Message(true, msg, default);
        }
        /// <summary>
        /// 返回成功
        /// </summary>
        /// <param name="msg">消息</param>
        /// <param name="response">数据</param>
        /// <returns></returns>
        public static MessageModel<T> Success(string msg, T response)
        {
            return Message(true, msg, response);
        }
        /// <summary>
        /// 返回失败
        /// </summary>
        /// <param name="msg">消息</param>
        /// <returns></returns>
        public static MessageModel<T> Fail(string msg = "操作失败")
        {
            return Message(false, msg, default);
        }
        /// <summary>
        /// 返回失败
        /// </summary>
        /// <param name="msg">消息</param>
        /// <param name="response">数据</param>
        /// <returns></returns>
        public static MessageModel<T> Fail(string msg, T response)
        {
            return Message(false, msg, response);
        }
        /// <summary>
        /// 返回消息
        /// </summary>
        /// <param name="success">失败/成功</param>
        /// <param name="msg">消息</param>
        /// <param name="response">数据</param>
        /// <returns></returns>
        public static MessageModel<T> Message(bool success, string msg, T response)
        {
            return new MessageModel<T>() { msg = msg, response = response, success = success };
        }

        /// <summary>
        /// 返回文件
        /// </summary>
        /// <param name="success"></param>
        /// <param name="msg"></param>
        /// <param name="list"></param>
        /// <param name="FileBytes"></param>
        /// <param name="ContentType"></param>
        /// <returns></returns>
        public static MessageModel<T> FilePathMessage(bool success, string msg, List<string> list, byte[] FileBytes, string ContentType)
        {
            return new MessageModel<T>() { success = success, msg = msg, list = list, FileBytes = FileBytes, ContentType = ContentType };
        }
    }

    public class MessageModel
    {
        /// <summary>
        /// 状态码
        /// </summary>
        public int status { get; set; } = 200;
        /// <summary>
        /// 操作是否成功
        /// </summary>
        public bool success { get; set; } = false;
        /// <summary>
        /// 返回信息
        /// </summary>
        public string msg { get; set; } = "";
        /// <summary>
        /// 返回数据集合
        /// </summary>
        public object response { get; set; }

        /// <summary>
        /// 文件流字节数组
        /// </summary>
        public byte[] FileBytes = null;
        /// <summary>
        /// 返回类型
        /// </summary>
        public string ContentType = string.Empty;

        /// <summary>
        /// 多个
        /// </summary>
        public List<string> list = null;
    }
}
